package main

import (
	"encoding/json"
	"fmt"
	"github.com/OwnLocal/goes"
	"net/url"
	"os"
)

var client *goes.Client

var host = "http://localhost:9200/"

var (
	ES_HOST = "localhost"
	ES_PORT = "9200"
)

//初始化
func init() {

	var err error

	client = goes.NewClient(ES_HOST, ES_PORT)

	if err != nil {

		print(err)
	}

}

func main() {

	path := "C:\\Users\\Administrator\\Desktop\\中国经纬度.json"

	file, _ := os.OpenFile(path, os.O_RDONLY, os.FileMode(7777))

	decoder := json.NewDecoder(file)

	datas := [] map[string]interface{}{}

	decoder.Decode(&datas)

	for _, v := range datas {

		data := v["children"]

		children := data.([]interface{})

		for _, city := range children {

			i := city.(map[string]interface{})

			fmt.Println(i)

			extraArgs := make(url.Values)

			Map := make(map[string]interface{})
			location := make(map[string]interface{})

			location["lat"] = i["lat"]
			location["lon"] = i["log"]
			Map["name"] = i["name"]
			Map["location"] = location

			d := goes.Document{
				Index:  "map_of_china",
				Type:   "map_of_china",
				Fields: Map,
			}

			response, _ := client.Index(d, extraArgs)


			fmt.Println(response)

		}
	}

}
